import dotenv from "dotenv";
import Koa from "koa";
import { koaBody } from "koa-body";
import { apiRouter } from "./routes";
import error from "./error";
import swagger from "./swagger";

dotenv.config();

const app = new Koa();

// 全局错误处理中间件
app.use(error());

// koaBody.json = true，默认是开启 application/json 正文解析的
app.use(koaBody()).use(apiRouter.routes()).use(apiRouter.allowedMethods());

// swagger 文档
if (process.env.APP_DEBUG === "true") {
  swagger(app);
}

app.listen(5555);

console.log(`🚀  Server ready at: http://localhost:5555`);
